﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson.Serialization.Attributes;

namespace YmtAuth.Domain.EventHistory
{
    /// <summary>
    /// 用户注册事件
    /// </summary>
    public class UserRegisterEvent : Entity<string>
    {
        [BsonIgnoreIfNull]
        [BsonElement("lId")]
        public string LoginId { get; set; }
        [BsonElement("uId")]
        public int UserId { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("mobile")]
        public string Mobile { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("mail")]
        public string LoginMail { get; set; }
        [BsonIgnoreIfNull]
        [BsonIgnoreIfDefault]
        [BsonElement("cIp")]
        public string ClientIp { get; set; }
        [BsonElement("cTime")]
        public DateTime CreateTime { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("desc")]
        public string Description { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("rSource")]
        public string RegSource { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("rRest")]
        public string RegResult { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("cSource")]
        public string ChannelSource { get; set; }
        [BsonIgnoreIfNull]
        [BsonElement("tSource")]
        public string TerminalSource { get; set; }
        public UserRegisterEvent(string loginId, int userId, string mobile = null, string mail = null, string clientIp = null
            , string desc = null, string rRest = null, string rSource = null, string sChannelSource = null, string sTerminalSource = null)
        {
            this.Id = Guid.NewGuid().ToString("N");
            this.LoginId = loginId;
            this.UserId = userId;
            this.Mobile = mobile;
            this.LoginMail = mail;
            this.ClientIp = string.IsNullOrEmpty(clientIp) ? null : clientIp;
            this.Description = desc;
            this.RegSource = rSource;
            this.RegResult = rRest;
            this.CreateTime = DateTime.Now;
            this.ChannelSource = sChannelSource;
            this.TerminalSource = sTerminalSource;
        }
        protected UserRegisterEvent() { }
        protected override IEnumerable<object> CompareValues()
        {
            yield return this.Id;
            yield return this.LoginId;
        }
    }
}
